import pytest
from appium.webdriver.common.mobileby import MobileBy
from app_wechat_po.base.base_page import BasePage


class AddressListPage(BasePage):
    # 点击添加成员
    def goto_add_member(self):
        # 2.点击【添加成员】
        self.swipe_find('添加成员').click()

        from app_wechat_po.page.add_member_page import AddMemberPage
        return AddMemberPage(self.driver)

    # 搜索联系人
    def search_contact_page(self,del_contactname):
        # 2.点击搜索、搜索删除的联系人
        self.find_and_click(MobileBy.XPATH, "//*[@text='天明科技']/../../../following-sibling::*/*[1]")
        # 输入联系人姓名
        self.fing_and_send(MobileBy.XPATH, "//*[@text='搜索']",del_contactname)

        result = self.wait_show("联系人")
        print(result)
        # 无搜索结果
        if not result:
            pytest.xfail(f"无搜索结果：{del_contactname}")
        # 有搜索结果、点击联系人
        del_contact_locator = (MobileBy.XPATH, f"//*[@text='联系人']/../following-sibling::*//*[@text='{del_contactname}']")
        self.find_and_click(*del_contact_locator)

        from app_wechat_po.page.personal_info_page import PersonalInfoPage
        return PersonalInfoPage(self.driver)
